package com.onehouse.infrastructure.repository.checkIn;

import com.onehouse.domain.checkIn.adapter.repository.IRoomDepositRepository;
import com.onehouse.domain.checkIn.model.valobj.RoomDeposit;
import com.onehouse.infrastructure.dao.RoomDepositDao;
import com.onehouse.infrastructure.dao.po.RoomDepositPO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;

@Repository
public class RoomDepositRepository implements IRoomDepositRepository {
    @Resource
    private RoomDepositDao roomDepositDao;

    @Override
    public void saveDeposit(String checkInRoomId, RoomDeposit roomDeposit) {
        RoomDepositPO po = new RoomDepositPO();
        po.setCheckInRoomId(checkInRoomId);
        po.setAmount(roomDeposit.getAmount());
        po.setPaymentId(roomDeposit.getPaymentId());
        roomDepositDao.insert(po);
    }

    @Override
    public void updateDeposit(String checkInRoomId, String paymentId) {
        RoomDepositPO po = new RoomDepositPO();
        po.setCheckInRoomId(checkInRoomId);
        po.setPaymentId(paymentId);
        roomDepositDao.update(po);
    }

    @Override
    public RoomDeposit getDeposit(String checkInRoomId) {
        RoomDepositPO po = roomDepositDao.selectByCheckInRoomId(checkInRoomId);
        if (po == null) {
            return null;
        }
        return RoomDeposit.builder()
                .amount(po.getAmount())
                .paymentId(po.getPaymentId())
                .build();
    }
} 